package com.breakfast.fun.adapter.user;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.breakfast.fun.R;
import com.breakfast.fun.base.BaseListAdapter;
import com.breakfast.fun.data.entity.user.address.RoadData;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by yukai on 16/9/16.
 */
public class ChooseRoadAdapter extends BaseListAdapter<RoadData> {
    public ChooseRoadAdapter(Context context, List<RoadData> list) {
        super(context, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_choose_area, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        RoadData data = getItem(position);
        holder.mTvItemChooseArea.setText(data.getAreaName());

        holder.mLlItemChooseArea.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(data);
            }
        });

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.tv_item_choose_area)
        TextView mTvItemChooseArea;
        @Bind(R.id.ll_item_choose_area)
        LinearLayout mLlItemChooseArea;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
